//
//  ApeDefine.h
//  ApeFoundation
//
//  Created by Eton on 2016/10/26.
//  Copyright © 2016年 ApeStar. All rights reserved.
//

#ifndef ApeDefine_h
#define ApeDefine_h

//公用Block
typedef void(^voidBlock)();
typedef void(^idBlock)(id obj);

//版本
#define SYSTEM_VERSION [[UIDevice currentDevice] systemVersion]
#define SYSTEM_VERSION_FLOAT [SYSTEM_VERSION floatValue]
//判断版本
#define IS_EQUAL_IOS(v) (SYSTEM_VERSION_FLOAT == v)//等于此版本
#define IS_GREATER_IOS(v) (SYSTEM_VERSION_FLOAT > v)//高于此版本
#define IS_LESS_IOS(v) (SYSTEM_VERSION_FLOAT < v)//低于此版本
#define IS_GREATER_EQUAL_IOS(v) (SYSTEM_VERSION_FLOAT >= v)//高于等于此版本
#define IS_LESS_EQUAL_IOS(v) (SYSTEM_VERSION_FLOAT <= v)//低于等于此版本

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

//屏幕宽高
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define NAV_BAR_HEIGHT 64.0f
#define TAB_BAR_HEIGHT 49.0f
#define VIEW_HEIGHT (SCREEN_HEIGHT - NAV_BAR_HEIGHT)

//相对于 750 宽的屏幕比例
#define SCREEN_WIDTH_SCALE_47 (SCREEN_WIDTH/375.0f)
#define SCREEN_HEIGHT_SCALE_47 (SCREEN_HEIGHT/667.0f)

//判断 屏幕尺寸
#define IS_SCREEN_55_INCH	(IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
#define IS_SCREEN_47_INCH	(IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_SCREEN_4_INCH	(IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_SCREEN_35_INCH	(IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)

//Color便利构造宏
#define RGB(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define RGBS(v) [UIColor colorWithRed:(v)/255.0f green:(v)/255.0f blue:(v)/255.0f alpha:1]

#define HEXA(hexValue,a) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:a]
#define HEX(hexValue)   HEXA(hexValue,1.0)

//主、子线程
#define kMainQueue dispatch_get_main_queue() //主线程队列
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //全局并发队列

//格式化 字符串
#define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__]

//便利化 UserDefaults
#define  kUserDefaults [NSUserDefaults standardUserDefaults]

//便利化 AppDelegate
#define  kAppDelegate [[UIApplication sharedApplication] delegate]

//便利化 AppWindow
#define kWindow [UIApplication sharedApplication].keyWindow

//便利化 定义 Weak Self
#define kWeakSelf __weak __typeof(self) weakSelf = self

//便利化 Docment文件夹目录
#define kDocumentPath NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject

//便利化 通过Storyboard ID 在对应Storyboard中获取场景对象
#define kVCFromSb(storyboardName, storyboardId)     [[UIStoryboard storyboardWithName:storyboardName bundle:nil] \
instantiateViewControllerWithIdentifier:storyboardId]

//便利化 通知
#define kNotification [NSNotificationCenter defaultCenter]
#define kNotificationPost(name) [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil]

//便利化 获取图片资源
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

//便利化 字体
#define kBoldSystemFont(font) [UIFont boldSystemFontOfSize:font]
#define kSystemFont(font) [UIFont systemFontOfSize:font]

//获取当前语言
#define kCurrentLanguage [[NSLocale preferredLanguages] firstObject]

//设置 view 圆角和边框
#define kViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

//由角度转换弧度 由弧度转换角度
#define kDToR(d) (M_PI * (d) / 180.0)
#define kRToD(r) (r*180.0)/(M_PI)


/**
 沙盒目录文件
 */
//获取temp
#define kPathTemp NSTemporaryDirectory()
//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//控制打印
#ifndef __OPTIMIZE__
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif

#endif /* ApeDefine_h */
